#ifndef OCK_HCPS_PIER_FUN_GUARD_UTILS_H
#define OCK_HCPS_PIER_FUN_GUARD_UTILS_H

namespace ock {
namespace utils {
template <typename AllocFunT = int (*)(), typename FreeFunT = int (*)()>
class FunGuard
{
private:
    bool releaseControl;
    FreeFunT freeFun;
public:
    explicit FunGuard(AllocFunT allocFun, FreeFunT freeFun) : releaseControl(false), freeFun(freeFun)
    {
        allocFun()
    }
    ~FunGuard()
    {
        if (!releaseControl) {
            freeFun()
        }
    }
    void ReleaseControl(void)
    {
        releaseControl = true;
        freeFun()
    }
};


template <typename AllocFunT, typename FreeFunT, typename AllocFunRetT = typename AllocFunT::result_type>
class FunGuardWithRet
{
private:
    bool releaseControl;
    FreeFunT freeFun;
    AllocFunRetT allocRet;
public:
    explicit FunGuardWithRet(AllocFunT allocFun, FreeFunT freeFun) : releaseControl(false), freeFun(freeFun)
    {
        allocRet = allocFun()
    }
    ~FunGuard()
    {
        if (!releaseControl) {
            freeFun()
        }
    }
    const AllocFunRetT &AllocRet(void) const 
    {
        return allocRet;
    }

    AllocFunRetT &AllocRet(void) const 
    {
        return allocRet;
    }


    void ReleaseControl(void)
    {
        releaseControl = true;
        freeFun()
    }
};
}
}
#endif